x86/p2m: free the paging memory pool preemptively
authorRoger Pau Monné <roger.pau@citrix.com>
Tue, 11 Oct 2022 12:24:21 +0000 (14:24 +0200)
committerJan Beulich <jbeulich@suse.com>
Tue, 11 Oct 2022 12:24:21 +0000 (14:24 +0200)
commite7aa55c0aab36d994bf627c92bd5386ae167e16e
treec7b81a28ce3adfe8578ff2e312f1ed179a268e7b
parentf50a2c0e1d057c00d6061f40ae24d068226052ad
x86/p2m: free the paging memory pool preemptively

The paging memory pool is currently freed in two different places:
from {shadow,hap}_teardown() via domain_relinquish_resources() and
from {shadow,hap}_final_teardown() via complete_domain_destroy().
While the former does handle preemption, the later doesn't.

Attempt to move as much p2m related freeing as possible to happen
before the call to {shadow,hap}_teardown(), so that most memory can be
freed in a preemptive way.  In order to avoid causing issues to
existing callers leave the root p2m page tables set and free them in
{hap,shadow}_final_teardown().  Also modify {hap,shadow}_free to free
the page immediately if the domain is dying, so that pages don't
accumulate in the pool when {shadow,hap}_final_teardown() get called.

Move altp2m_vcpu_disable_ve() to be done in hap_teardown(), as that's
the place where altp2m_active gets disabled now.

This is part of CVE-2022-33746 / XSA-410.

Reported-by: Julien Grall <jgrall@amazon.com>
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Tim Deegan <tim@xen.org>
xen/arch/x86/domain.c
xen/arch/x86/mm/hap/hap.c
xen/arch/x86/mm/shadow/common.c